package api;

import conf.App;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripts.TestAddUser;
import util.HttpClientUtil;
import util.ResponseData;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

public class AddUserApi {
    private static final String addUserUrl= App.BASE_URL+"/member/member/addUserSubmit";
    private static final String updateUrl=App.BASE_URL+"/member/member/editUsersubmit";
    private static final Logger logger= LoggerFactory.getLogger(TestAddUser.class);
    /**
     *添加用户
     * @param name 用户名
     * @param phone 手机号吗
     * @param pwd 密码
     * @param rePwd 确认密码
     * @param role 用户角色
     * @return 返回数据
     */
    public static ResponseData add_user(String name,String phone,String pwd,String rePwd,int role) throws IOException, URISyntaxException {
        Map<String,String> data=new HashMap<>();
        data.put("name",name);
        data.put("phone",phone);
        data.put("pwd",pwd);
        data.put("rePwd",rePwd);
        data.put("role", String.valueOf(role));
        return HttpClientUtil.post_form(addUserUrl, data);
    }
    public static ResponseData  userPwdUpdate(String id,String pwd,String rePwd,String pwd_attach) throws IOException, URISyntaxException {
        logger.info("id={} pwd={} rePwd={} pwd_attach={} ",id,pwd,rePwd,pwd_attach);
        Map<String,String> data=new HashMap<>();
        data.put("id",id);
        data.put("pwd",pwd);
        data.put("rePwd",rePwd);
        data.put("pwd_attach",pwd_attach);
        return HttpClientUtil.post_form(updateUrl, data);
    }
}
